import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

///自定义输入框
class RecordFieldWidget extends StatefulWidget {
  const RecordFieldWidget({
    Key key,
    @required this.controller,
    this.maxLength: 16,
    this.autoFocus: false,
    this.focusNode,
    this.placeHolder,
    this.isInputPwd: false,
  }) : super(key: key);

  final TextEditingController controller;
  final int maxLength;
  final bool autoFocus;
  final FocusNode focusNode; //焦点
  final String placeHolder;
  final bool isInputPwd;

  @override
   _MyTextFieldState createState() => _MyTextFieldState();
}

class _MyTextFieldState extends State<RecordFieldWidget> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return  ConstrainedBox(
      constraints: BoxConstraints(
          maxHeight: 48,
      ),
      child: TextField(
        autocorrect: false,
        textAlign: TextAlign.right,
        controller: widget.controller,
        style: TextStyle(color: Color(0xff333333), fontSize: 14.0),
        maxLength: widget.maxLength,
        keyboardType: TextInputType.number,
        inputFormatters: <TextInputFormatter>[LengthLimitingTextInputFormatter(7)],
        autofocus: widget.autoFocus,
        decoration: InputDecoration(
          hintText: widget.placeHolder,
          hintStyle: TextStyle(color: Color(0xFF999999), fontSize: 14.0),
          counterText: '',
          focusedBorder: UnderlineInputBorder(
              borderSide: BorderSide(
                color: Colors.white,
                width: 0.0,
              )
          ),
          enabledBorder: UnderlineInputBorder(
              borderSide: BorderSide(
                color: Colors.white,
                width: 0.0,
              )
          ),
        ),
      ),
    );
  }
}
